//  Created by Mathew Purchase.
//  Copyright (c) 2014 Mathew Purchase. All rights reserved.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

//[RequireComponent (typeof (Inventory))]

public class settlementPiece : terrainPiece 
{

	//---------------------------------------------------------------------------------------------
	// Properties
	public string SettlementName;
	public int population;
	public int SettlementType;
	public int gold;

	
	
	//---------------------------------------------------------------------------------------------
	// Members
	
	helpRandomName nameService;
	public Character_NPC m_NPC;
	Inventory m_storeHouse;
	public List<Character_NPC> m_populous;
	public GameObject m_NPCContainer;
	
	//---------------------------------------------------------------------------------------------
	// Events and Delegates
	
	
	//---------------------------------------------------------------------------------------------
	// Init
	
	void Start () 
	{
		
		nameService = GameObject.Find("NameService").GetComponent<helpRandomName>();
		m_storeHouse = GetComponent<Inventory>();
		PopulateSettlement();
		int randomName = Random.Range(0,nameService.settlementNames.Count);
		SettlementName = nameService.settlementNames[randomName];
		
	}
	
	//---------------------------------------------------------------------------------------------
	// Core Functions

	void PopulateSettlement()
	{
		population = Random.Range (10,60);
		
		for (int a = 0; a < population; a++)
		{
			Character_NPC citizen = Instantiate (m_NPC, gameObject.transform.position, Quaternion.identity) as Character_NPC;
			citizen.transform.parent = m_NPCContainer.gameObject.transform;
			citizen.m_homeTown = this;
			citizen.m_homeTownStore = m_storeHouse;
			
			// Randomise NPC Class (TO BE REPLACED BY SETTLEMENT TYPE BREAKDOWNS)
			{
				int dice = Random.Range (0,10);
				citizen.NPC_ClassID = dice;
				gold = m_populous.Count * 100;
			}
			
			citizen.NPCInit();
			
			m_populous.Add(citizen);
			
			
			
			
			
		}
		
	}
	
}
